package com.youshang.config;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class ThreadPoolConfig {

    /**
     * 定时任务用的线程池
     * @return
     */
    @Bean("taskThreadPool")
    public ThreadPoolExecutor taskThreadPool(){
        return new ThreadPoolExecutor(30,
                300,
                180,
                TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<>(100000),
                new ThreadFactoryBuilder().setNameFormat("dr-company-task-%d").build());
    }
}
